/*
路由化 
 */
const express = require('express')
const router = express()
const { createToken } = require('../jwt/index')
const { status200 } = require('../util/status')
const { url } = require('../upload')
const syncRequest = require('sync-request')
const fs = require('fs')





//获取token信息
router.post('/api/login', (req, res) => {
    console.log('登录接口')
    const { username, password } = req.body
    let token = createToken(req.body)
    if (username == 'admin' && password == 'aa123456') {
        res.send({
            code: 0,
            msg: 'success',
            data: {
                // accessToken: "sdjhfjkhdsf",
                accessToken: token,
                avatar: "https://img0.baidu.com/it/u=3336352396,199235418&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=625",
                expires: "2030/10/30 00:00:00",
                // refreshToken: "sdfhjsdhf",
                refreshToken: token,
                roles: ['admin'],
                username: "admin",
                id: '1234567891'
            }
        })
    }
    else if (username == 'common' && password == 'aa123456') {
        res.send({
            code: 0,
            msg: 'success',
            data: {
                accessToken: "sdjhfjkhdsf",
                avatar: "https://img1.baidu.com/it/u=4079575215,2612068509&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=1093",
                expires: "2030/10/30 00:00:00",
                refreshToken: "sdfhjsdhf",
                roles: ['common'],
                username: "common",
                id: '1234567890'
            }
        })
    }
    else {
        res.send({
            code: 500,
            msg: '登录失败,请重新登录'
        })
    }
})


// 暂时设置
// 只设置管理员路由
const adminRoutes = [
    {
        path: "/system",
        meta: {
            icon: "ri:settings-3-line",
            title: "menus.pureSysManagement",
            rank: 14
        },
        children: [
            {
                path: "/system/user/index",
                name: "SystemUser",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.pureUser",
                    roles: ["admin"]
                }
            },
            {
                path: "/system/role/index",
                name: "SystemRole",
                meta: {
                    icon: "ri:admin-fill",
                    title: "menus.pureRole",
                    roles: ["admin"]
                }
            },
        ]
    },
    {
        path: "/wangs",
        meta: {
            icon: "ri:settings-3-line",
            title: "menus.pureWangs",
            rank: 14
        },
        children: [
            {
                path: "/wangs/wa-upload",
                name: "wangsUpload",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsUpload",
                    roles: ["admin"]
                }
            },
            {
                path: "/wangs/wa-table",
                name: "wangsTable",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsTable",
                    roles: ["admin"]
                }
            },
            {
                path: "/wangs/wa-button",
                name: "wangsButton",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsButton",
                    roles: ["admin"]
                }
            },
            {
                path: "/wangs/wa-only",
                name: "wangsOnly",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsOnly",
                    roles: ["admin"]
                }
            },
            /* vue-plugins-print */
            {
                path: "/wangs/wa-print",
                name: "wangsPrint",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsPrint",
                    roles: ["admin"]
                }
            },
            /* io页面 */
            {
                path: "/wangs/wa-Io",
                name: "wangsIo",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsIo",
                    roles: ["admin"]
                }
            },
            /* 工作流 */
            {
                path: "/wangs/wa-flow",
                name: "wangsFlow",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsFlow",
                    roles: ["admin"]
                }
            },
            /* iviewtable 可能需要解决table滚动条的问题 */
            {
                path: "/wangs/wa-iview",
                name: "wangsIview",
                meta: {
                    icon: "ri:admin-line",
                    title: "menus.wangsIview",
                    roles: ["admin"]
                }
            }
            
        ]
    }
]


//获取route路由信息
router.get('/api/getRoutes', (req, res) => {
    res.send({
        code: 0,
        msg: 'success',
        data: adminRoutes
    })
})




/* onlyOffice前端关闭后自动保存 */
router.post('/api/save', (req, res) => {
    const path = url + '/' + 'test4500.doc'
    console.log(path, 'path')
    if (req.body.status == 2) {
        const file = syncRequest("GET", req.body.url)
        fs.writeFileSync(path, file.getBody())
        res.write("{\"error\":0}")
        res.end()
    }
})


/* print打印接口 */
router.post('/api/getPrintData', (req, res) => {
    const arr = [
        {
            id: "id编号",
            good: '货物',
            nums: '数量',
            supply: '供应商',
            address:'供应商地址',
            qrcode: '二维码'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        },
        {
            id: "23423554356",
            good: 't1螺丝',
            nums: '232',
            supply: '海南xxx螺丝制造厂',
            address:'海南省海口市xx路xx号',
            qrcode: 'http://127.0.0.1:9066/qrcode.png'
        }
    ]
    status200(res, { data: { data: arr } })
})


module.exports = router